{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form gg-form-bar border-t border-x">

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="doDate" id="pp_time" readonly placeholder="日期" class="layui-input" autocomplete="off"/>
    </div>

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderNum" placeholder="单据编号" class="layui-input" autocomplete="off"/>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <select name="se_type" id="se_type" lay-filter="se_type">
            <option value="1">入库</option>
            <option value="2">出库</option>
        </select>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <select name="yw_type" id="yw_type">
            <option value="">业务类型</option>
            <option value="采购收货">采购收货</option>
            <option value="销售退货">销售退货</option>
            <option value="生产入库">生产入库</option>
            <option value="委外收货">委外收货</option>
            <option value="生产退料">生产退料</option>
            <option value="委外退料">委外退料</option>
            <option value="报废入库">报废入库</option>
            <option value="其他入库">其他入库</option>
            <option value="调拨入库">调拨入库</option>
            <option value="盘盈入库">盘盈入库</option>
        </select>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="pName" placeholder="往来单位" class="layui-input" autocomplete="off"/>
    </div>

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="mdTypeName" placeholder="物料类别" class="layui-input" autocomplete="off"/>
    </div>

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="bar_code" placeholder="物料编码" class="layui-input" autocomplete="off"/>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="mdName" placeholder="物料名称" class="layui-input" autocomplete="off"/>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="specs" placeholder="规格型号" class="layui-input" autocomplete="off"/>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="wName" placeholder="仓库" class="layui-input" autocomplete="off"/>
    </div>


    <div class="layui-input-inline" style="width:150px;">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i
                class="layui-icon layui-icon-search mr-1"></i>搜索
        </button>
        <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
    </div>
</form>
<div class="p-3">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--  	<button class="layui-btn layui-btn-sm addNew" type="button">+ 添加期初</button>-->
        <!--  	<button class="layui-btn layui-btn-sm import" type="button">批量导入</button>-->
        <!--      <button class="layui-btn layui-btn-sm layui-btn-primary" id="import" >导入</button>-->
        <!--      <a href="{__EXPORTMODE__}/期初导入模板.xlsx" download="" class="layui-btn layui-btn-sm layui-btn-primary">导入模板</a>-->
        <!--  	<button class="layui-btn layui-btn-sm layui-btn-danger del" lay-event="del" type="button">删除</button>-->
    </div>
</script>
<script type="text/html" id="actionBar">
    <button class="layui-btn layui-btn-normal  layui-btn-xs" lay-event="edit">编辑</button>
    <!--    <!--    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>-->-->
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    var mStatus = ['', '未对账', '部分对账', '已对账'];
    const moduleInit = ['tool'];

    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form, laydate = layui.laydate;
        var upload = layui.upload;
        var tableIns = table.render({
            elem: '#test'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter', 'exports']
            , title: '期初档案'
            , url: "{:url('index')}"
            , page: true
            , cellMinWidth: 80
            , cols: [[
                // {type: 'checkbox', fixed: 'left' },
                // {fixed: 'left',field: 'id',title: 'ID' ,unresize: true,hide:true},
                // {field:'id',width:80, title: 'ID号', align:'center'}
                // ,{field:'pCode',title: '客户编码'}
                {field: 'doDate', title: '日期'}
                , {field: 'orderNum', title: '单据编号'}
                , {field: 'yw_type', title: '业务类型'}
                , {field: 'pName', title: '往来单位'}
                , {field: 'mdTypeName', title: '物料类别'}
                , {field: 'bar_code', title: '物料编码'}
                , {field: 'mdName', title: '物料名称'}
                , {field: 'specs', title: '规格型号'}
                , {field: 'unit', title: '单位'}
                , {field: 'wName', title: '仓库'}
                , {field: 'inNum', title: '入库数量'}
                , {field: 'sendNum', title: '出库数量'}
                // ,{title: '操作',fixed: 'right',width: 200, align:'center', toolbar: '#actionBar'}
            ]]
        });
        //监听搜索提交
        form.on('submit(webform)', function (data) {
            console.log('data', data)
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        table.on('tool(test)', function (obj) {
            if (obj.event === 'edit') {
                tool.side("{:url('add')}?id=" + obj.data.id);
            }
            if (obj.event === 'forbid') {
                layer.confirm('确定要禁用该类别吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            tableIns.reload();
                        }
                    }
                    tool.post("{:url('reuse')}", {id: obj.data.id, status: 2}, callback);
                    layer.close(index);
                });
            }
            if (obj.event === 'resume') {
                layer.confirm('确定要启用该类别吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            tableIns.reload();
                        }
                    }
                    tool.post("{:url('reuse')}", {id: obj.data.id, status: 1}, callback);
                    layer.close(index);
                });
            }
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("{:url('delete')}", {id: obj.data.id}, callback);
                    layer.close(index);
                });
            }
        });
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch (obj.event) {
                case 'add':
                    break;
                case 'del':
                    var data = checkStatus.data;
                    var ids = []
                    if (data.length) {
                        data.forEach(function (value, index) {
                            console.log('value', value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            tool.delete("{:url('delete')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    } else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'import':

                    break;

            }
            ;
        })
        $('body').on('click', '.addNew', function () {
            tool.side("{:url('add')}?");
        });

        upload.render({
            elem: '#import'
            , url: "{:url('importData')}"
            , accept: 'file'
            , exts: 'xlsx'
            , done: function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    location.reload()
                }, 2000)
            }
        });
        laydate.render({
            elem: '#pp_time'
            , type: 'date',
            range: '~'
        });

        form.on('select(se_type)', function (data) {
            let seType = data.value;
            let inType = ['采购收货',
                '销售退货',
                '生产入库',
                '委外收货',
                '生产退料',
                '委外退料',
                '报废入库',
                '其他入库',
                '调拨入库',
                '盘盈入库'];
            let outType = ['销售发货',
                '采购退货',
                '生产领料',
                '委外发货',
                '委外退货',
                '其他出库',
                '调拨出库',
                '盘亏出库'];
            let types = [];
            if (seType == 1) {
                types = inType;
            } else {
                types = outType;
            }
            let str = '<option value="">业务类型</option>';
            for (var i = 0; i < types.length; i++) {
                str += '<option value="' + types[i] + '">' + types[i] + '</option>';
            }
            $("#yw_type").empty();
            $("#yw_type").append(str);
            form.render()
        });
    }
</script>
{/block}
<!-- /脚本 -->